import { editSysUserApi } from '@/api/custcare/sysuser/sysuser'
import { SetSysUser } from '@/api/custcare/sysuser/SysUserModel'
import useInstance from '@/hooks/useInstance'
import { StatusCode } from '@/http/request'
import { number } from 'echarts'
import { reactive } from 'vue'

export default function useSysUser(getSysUserList: any) {
    const { global } = useInstance()

    // 设置
    const setSysUserBtn = async (id: number, isService: boolean) => {
        let tip = '确定设置成客服吗？'
        if (isService == false) {
            tip = '确定移除客服吗？'
        }
        const confirm = await global.$eleConfirm(tip)
        if (confirm) {
            let param = reactive<SetSysUser>({
                id: id,
                is_service: isService
            })
            let res = await editSysUserApi(param)
            if (res && res.code == StatusCode.Success) {
                // 刷新列表
                getSysUserList()
                // 信息提示
                global.$message({ message: res.msg, type: 'success' })
            }
        }
    }
    return {
        setSysUserBtn
    }
}
